<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态信息网页</title>
    <link href="https://cdn.tailwindcss.com" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="styles.css">
</head>
<body class="bg-gray-50">
    <div class="container mx-auto px-4 py-8 max-w-4xl">
        <header class="text-center mb-8">
            <h1 class="text-4xl font-bold text-gray-800 mb-2">动态信息网页</h1>
            <p class="text-gray-600">分享你的想法，参与讨论</p>
        </header>

        <!-- 发布新文章按钮 -->
        <div class="mb-6 text-center">
            <button id="showPostForm" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded-lg transition duration-300">
                <i class="fas fa-plus mr-2"></i>发布新信息
            </button>
        </div>

        <!-- 发布文章表单 -->
        <div id="postFormContainer" class="hidden mb-8 bg-white p-6 rounded-lg shadow-md">
            <h2 class="text-2xl font-bold mb-4 text-gray-800">发布新信息</h2>
            <form id="postForm">
                <div class="mb-4">
                    <label class="block text-gray-700 text-sm font-bold mb-2" for="postTitle">
                        标题 *
                    </label>
                    <input type="text" id="postTitle" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700 text-sm font-bold mb-2" for="postContent">
                        内容 *
                    </label>
                    <textarea id="postContent" rows="4" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required></textarea>
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700 text-sm font-bold mb-2" for="postAuthor">
                        昵称 *
                    </label>
                    <input type="text" id="postAuthor" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
                </div>
                <div class="flex space-x-4">
                    <button type="submit" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded transition duration-300">
                        <i class="fas fa-paper-plane mr-2"></i>发布
                    </button>
                    <button type="button" id="cancelPost" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded transition duration-300">
                        取消
                    </button>
                </div>
            </form>
        </div>

        <!-- 文章列表 -->
        <div id="postsContainer" class="space-y-6">
            <div class="text-center text-gray-500">
                <i class="fas fa-spinner fa-spin mr-2"></i>加载中...
            </div>
        </div>
    </div>

    <!-- 文章模板 -->
    <template id="postTemplate">
        <div class="bg-white rounded-lg shadow-md p-6">
            <div class="flex justify-between items-start mb-4">
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-2 post-title"></h3>
                    <p class="text-sm text-gray-600">
                        <i class="fas fa-user mr-1"></i>
                        <span class="post-author"></span>
                        <span class="mx-2">•</span>
                        <i class="fas fa-clock mr-1"></i>
                        <span class="post-date"></span>
                    </p>
                </div>
                <button class="text-blue-500 hover:text-blue-700 toggle-comments">
                    <i class="fas fa-comments mr-1"></i>
                    <span class="comment-count">0</span> 评论
                </button>
            </div>
            <p class="text-gray-700 mb-4 post-content"></p>
            
            <!-- 评论区 -->
            <div class="comments-section hidden mt-4 pt-4 border-t">
                <h4 class="font-bold mb-3">评论</h4>
                <div class="comments-list space-y-3 mb-4"></div>
                
                <!-- 添加评论表单 -->
                <form class="comment-form">
                    <div class="mb-3">
                        <input type="text" class="comment-author w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="你的昵称" required>
                    </div>
                    <div class="mb-3">
                        <textarea class="comment-content w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" rows="2" placeholder="写下你的评论..." required></textarea>
                    </div>
                    <button type="submit" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded transition duration-300">
                        <i class="fas fa-comment mr-2"></i>发表评论
                    </button>
                </form>
            </div>
        </div>
    </template>

    <script src="script.js"></script>
</body>
</html>
